<template>
  <div>
    <form @submit.prevent="modifySubject()">
      <div class="mb-3 row">
        <label class="col-sm-2 col-form-label">学科名称</label>
        <div class="col-sm-10">
          <input
            type="text"
            class="form-control"
            v-model="subject.sname"
            required="required"
          />
        </div>
      </div>
      <button type="submit" class="btn btn-secondary">提交</button>
      |
      <router-link to="/subject/list" class="btn btn-secondary"
        >返回</router-link
      >
    </form>
  </div>
</template>

<script>
export default {
  name: "SubjectModify",
  data() {
    return {
      subject: {
        id: 0,
        sname: "",
      },
    };
  },
  props: {
    id: {
      type: String,
      default: null,
    },
  },
  mounted() {
    this.$parent.subjectTitle = "学科修改";
    this.getSubject();
  },
  methods: {
    getSubject() {
      this.axiosJSON.get("/subject/getOne?id=" + this.id).then((result) => {
        this.subject = result.data.data;
      });
    },
    modifySubject() {
      this.axiosJSON.post("/subject/update", this.subject).then((result) => {
        if (result.data.code == 0) {
          this.$message({ type: "success", message: result.data.msg });
          this.$router.push({ path: "/subject/list" });
          // this.$router.push("/subject/list"); //编程方式跳转到部门列表组件
        } else {
          this.$message.error(result.data.msg);
        }
      });
    },
  },
};
</script>

<style>
</style>